<?php
  require_once('./includes/header.php');

  if(isset($_SESSION['id']) && !empty($_SESSION['id'])){
    header("location:show_all_users.php");
    exit;
  }


  if(isset($_POST['email']) && !empty($_POST['email']))
  {
    $email = mysql_real_escape_string(trim($_POST['email']));

    $where = "`email`='$email' AND `status`='1'";

    /*******************************/
    $result = fetchAll('users',$where);
    /*******************************/
    $ans = mysql_fetch_assoc($result);
    $rows = mysql_num_rows($result);
    if($rows == 1){
#################################################################
$to = $email;
$subject = 'mysite.com : Forgot Pasword';
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
//$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
//$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
//$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
//$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";


echo $link = getForgotPasswordLink($ans['id']);
//echo "<hr>";
//echo decrypt($link);

$message = <<<MSG
Dear $ans[uname] ,
<p>
  Please click the link below to change password.
</p>
<p>
  $link
</p>
<p>
  If above link will is not working then please copy paste above link on browser.
</p>

Best Regards !<br>
mysite.com<br>
MSG;
//mail($to, $subject, $message, $headers);

#################################################################


    } else {
      $msg = "<strong>$email</strong> is not registered with us.";
    }
    //pr($rows);
  } else {
    if(!empty($_POST)){
      $msg = "Email should not be blank.";
    }
  }
?>
<!------------------HEADER ENDS-------------------------->

      <div class="row">

<?php
if($msg != '') {
?>
    <div class="alert alert-danger fade in">
      <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
      <p><?=$msg?></p>
    </div>
<?php
}
?>

        <h2 class="form-signin-heading">Please enter your registered email id</h2>

<!----------------  FORM ------------>
      <form method="post" class="form-signin" role="form">
        <input name="email" value="<?=@$_COOKIE['email']?>" type="email123" class="form-control" placeholder="Email address"  autofocus>
        <br>
        <button class="btn btn-lg btn-primary btn-block" type="submit">Recover Password </button>
        <a href="login.php">Login</a>
      </form>

<!----------------  FORM ------------>
      </div>
<!-------------- FOOTER START --------------------------->
    <!-- Custom styles for this template -->
    <link href="css/signin.css" rel="stylesheet">
<?php
  require_once('./includes/footer.php');
?>
